package com.ruoyi.hospital.service.impl;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.core.domain.hospital.ActPatList;
import com.ruoyi.common.core.domain.hospital.PostResult;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.datasource.DynamicDataSourceContextHolder;
import com.ruoyi.hospital.mapper.ActPatListMapper;
import com.ruoyi.hospital.service.IActPatListService;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ActPatListServiceImpl implements IActPatListService {

    @Autowired
    ActPatListMapper actPatListMapper;

    @Override
    @DataSource(value = DataSourceType.SLAVE)
    public List<ActPatList> getActPatList(ActPatList actPatList) {
//        DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SLAVE.name());
        List<ActPatList> list = actPatListMapper.getActPatList(actPatList);
//        DynamicDataSourceContextHolder.clearDataSourceType();
        return list;
    }

    @Override
    public Integer getActPatListCount(ActPatList actPatList) {
        DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SLAVE.name());
        Integer total = actPatListMapper.getActPatListCount(actPatList);
        DynamicDataSourceContextHolder.clearDataSourceType();
        return total;
    }

    @Override
    public int addActPatList(ActPatList actPatList) {
        ActPatList enty = actPatListMapper.findById(actPatList.getId());
        if(enty == null){
            return actPatListMapper.addActPatList(actPatList);
        }else{
            return actPatListMapper.updateActPatList(actPatList);
        }
    }

    @Override
    public int updateActPatList(ActPatList actPatList) {
        return actPatListMapper.updateActPatList(actPatList);
    }

    @Override
    public List<PostResult> selectPostResultList(PostResult postResult) {
        return actPatListMapper.selectPostResultList(postResult);
    }
}

